/*
 * MobileSearchView.fx
 *
 * Created on 06/05/2009, 19:06:40
 */

package webooksfx_desktop.view;

import javafx.ext.swing.SwingTextField;
import javafx.scene.Group;
import javafx.scene.Node;
import webooksfx.model.Servicio;
import webooksfx.view.SearchView;
import webooksfx_desktop.view.components.LoadingWindow;
import webooksfx_desktop.view.components.ViewColeccionLibrosComponent;
import webooksfx_desktop.view.components.ViewMessage;
import webooksfx_desktop.view.search.OptionsView;
import javafx.scene.input.KeyEvent;

/**
 * @author matias
 */

public class DesktopSearchView extends SearchView {
	var textBox: SwingTextField = null;
	var frameLibros: Node = null;
	var optionsView: OptionsView = null;
	var loading: LoadingWindow = LoadingWindow {
		width: 300
		height: 80
		translateX: 150
		translateY: 300
	}
	var view_msg: ViewMessage = null;

	override function show () : Void {
		super.show();
		optionsView.focoSobreTexto();
	}


	override function onServiciosChange() : Void{
		optionsView.generarServicios();
	}

	override public function showLoading () : Void {		
		loading.showLoad();
	}
	override public function hideLoading () : Void {
		loading.hideLoad();
	}

    override public function showResult() : Void{
		frameLibros = ViewColeccionLibrosComponent{
			coleccionLibros: bind coleccionLibros
			action: showDetail;
			actionPage: showPage;
			pag_actual: pag_actual;
		}
	}

	// ViewColeccionLibrosComponent.action
	public function showDetail (id_libro : String) : Void {
		this.searchControl.showDetail(this.servicioSeleccionado.id, id_libro);
	}
	// ViewColeccionLibrosComponent.actionPage
	public function showPage (num_pag: Integer) : Void {
		this.pag_actual = num_pag;
		this.search();
	}

	override public function showException (msg: String) : Void {
		this.hideLoading();
		view_msg = ViewMessage {
			type_msg: ViewMessage.ERROR
			x: 125
			y: 225
			text: msg
		}
		view_msg.show();
	}

    public override function create(): Node {
        this.node = Group {
            visible: false;
            content: [
                Group {
					translateY: 55;
					content: bind frameLibros;
				},
				optionsView = OptionsView{
					servicios: bind servicios;
					servicioSeleccionado: bind servicioSeleccionado;
					actionServicio: function (s : Servicio):Void{
						servicioSeleccionado = s;
					}
					actionBusqueda: function ( query : String, filtro : String ){
						this.pag_actual = 1;
						this.query = query;
						this.criterio = filtro;
						search();
					}
				},
				loading,
				Group {
					content: bind view_msg;
				}
            ]
        };
		return node;
    }
}